﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Caching;
using StripeOne.Blog.Base.Configuration;
using StripeOne.Core.Models;
using System.IO;
using System.Xml.Linq;
using StripeOne.Core.Cache;
using System.Web.Routing;

namespace StripeOne.Blog.Base
{
    public abstract class StripeOneController : Controller
    {
        public StripeOneController() { }

        protected virtual bool RequireAuthentication { get { return false; } }
        
        protected bool IsAjaxRequest()
        {
            return HttpContext.Request.Headers["X-Requested-With"] == "XMLHttpRequest";
        }

        protected override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            base.OnActionExecuting(filterContext);
            string currentUrl = filterContext.HttpContext.Request.Url.ToString();

            if (this.RequireAuthentication)
                filterContext.Result = Redirect("~/Login/Index?refUrl=" + currentUrl);
        }
    }
}